<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
            text-decoration: none;
        }
        .box {
            width: 350px;
            height: 400px;
            background: yellowgreen;
            margin: 0 auto;
            border: 1px solid black;
            text-align: center;
        }
        .box1 {
            display: flex;
            float: right;
        }
        h2 {
            display: none;
            color: white;
        }
        h1 {
            height: 60px;
            line-height: 60px;
            background: yellow;
        }
        p {
            display: block;
            font-size: 12px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div class="box">
        <h1>登录页</h1>
        <div class="box1">
            <h2>欢迎<span>xxx</span>登录</h2>
            <p>亲，<a href="javascript:;">请登录账号</a></p>
        </div>
    </div>
</body>
</html>

<script src="./cookie.js"></script>
<script>
    function $(tag) {
        return document.querySelector(tag)
    }
    var username = getCookie('username')
    if(username != "") {
        $('h2').style.display = 'block';
        $('p').style.display = 'none';
        $('span').innerHTML = username;
    } else {
        $('h2').style.display = 'none';
        $('p').style.display = 'block';
    }
    $('a').onclick = function() {
        location.href = 'login.html'
    }
</script>